﻿namespace Harness.Verificators
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using mshtml;

    internal class CheckVerificator : IVerificator
    {
        #region Constants

        private const int LocatorArgIndex = 0;
        private const int BoolArgIndex = 1;

        #endregion

        #region Public Methods

        public void SyntaxCheck(IHarness harness, IEnumerable<object> args)
        {
            if (null == args.ElementAtOrDefault(LocatorArgIndex))
            {
                throw new ArgumentNullException((LocatorArgIndex + 1).ToString() + ":Locator");
            }
        }

        public bool Verify(IHarness harness, IEnumerable<object> args)
        {
            string locator = (args.ElementAtOrDefault(LocatorArgIndex) ?? string.Empty).ToString();
            bool b = bool.Parse((args.ElementAtOrDefault(BoolArgIndex) ?? bool.TrueString).ToString());

            IHTMLElement element = IE.Element.Find(locator, IE.ActiveDocument);
            harness.HighlightElement(element);

            return b == IE.Element.IsChekced(element);
        }

        #endregion
    }
}
